//
//  NSMutableAttributedString+Category.m
//  OCDemo
//
//  Created by zhumuzhi on 2022/2/12.
//

#import "NSMutableAttributedString+Category.h"

@implementation NSMutableAttributedString (Category)

// 展示售价方法
+ (NSMutableAttributedString *) productPriceText:(NSString *)nowPrice marketPrice:(NSString *)marketPrice {
    // 当前价格(需要手动添加人民币符号)
    NSString *presentPrice = [NSString stringWithFormat:@"￥%@ ",nowPrice];
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:presentPrice
                                                                               attributes:@{NSForegroundColorAttributeName:MZRGBCOLOR(230, 51, 37),
                                                                                            NSFontAttributeName:[UIFont boldSystemFontOfSize:18.0]
                                                                                            }];
    
    // 过去价格(需要手动添加人民币符号)
    // NSString *oldString = [NSString stringWithFormat:@"%@ ",_singleModel.product_price];
    NSString *price = [NSString stringWithFormat:@"￥%@ ",marketPrice];
    NSMutableAttributedString *oldPrice = [[NSMutableAttributedString alloc] initWithString:price
                                                                                 attributes:@{NSForegroundColorAttributeName:MZRGBCOLOR(132, 132, 132),
                                                                                              NSFontAttributeName:[UIFont systemFontOfSize:12.0],
                                                                                              NSStrikethroughStyleAttributeName:@(2)}];
    // 把两个价格拼接一下
    [string insertAttributedString:oldPrice atIndex:string.length];
    // 把拼接完成的string返回
    return string;
}

@end
